
class Vertex:
    def __init__(self, id, label):
        self.id = id
        self.label = label
        self.incident_edges = set([])
            
    def add_incident_edge(self, incident_edge):
        self.incident_edges.add(incident_edge)

    def debug(self):
        print self.id,
        print self.label

class Edge:
    def __init__(self, id, label, v1, v2):
        self.id = id
        self.label = label
        self.v1 = v1
        self.v2 = v2
    
    def get_vertices(self):
        return set([self.v1, self.v2])
    
    def debug(self):
        print self.id,
        print self.v1,
        print self.v2,
        print self.label

class Attribute:
    def __init__(self, name, value):
        self.name = name
        self.value = value
    
    def debug(self):
        print self.name,
        print self.value

class Graph:
    def __init__(self, id):
        self.id = id
        self.Vertices = {}
        self.Edges = {}
        self.Attributes = {}

    def add_vertex(self, id, label):
        curr_vertex = Vertex(id, label)
        self.Vertices[id] = curr_vertex 
       
    def add_edge(self, id, v1, v2, label):
        curr_edge = Edge(id, label, v1, v2)
        self.Edges[id] = curr_edge
        self.Vertices[v1].add_incident_edge(id)
        self.Vertices[v2].add_incident_edge(id)
        
    def add_attribute(self, name, value):
        curr_attribute = Attribute(name,value)
        self.attribute[name] = curr_attribute

    def debug(self):
        print "Graph Id: ",
        print self.id
        for vertex_id in sorted(self.Vertices.keys()):
            self.Vertices[vertex_id].debug()
        for edge_id in sorted(self.Edges.keys()):
            self.Edges[edge_id].debug()
        for attribute_name in self.Attributes.keys():
            self.Attributes[attribute].debug()
                  
class GraphDb:
    def __init__(self):
        self.Graphs = {}
        
    def add_graph(self, graph):
        self.Graphs[graph.id] = graph

    def debug(self):
        for graph_id in sorted(self.Graphs.keys()):
            self.Graphs[graph_id].debug()
        
class Instance:
    def __init__(self, id, graph_id):
        self.id = id
        self.graph_id = graph_id
        self.Vertices = set([])
        self.Edges = set([])

    def change_id(self,id):
        self.id = id
        
    def add_vertex(self, vertex):
        self.Vertices.add(vertex)

    def add_edge(self, edge):
        self.Edges.add(edge)

    def debug(self):
        print "Instance Id: ",
        print self.id
        print "Graph Id: ",
        print self.graph_id
        print self.Vertices
        print self.Edges

class InstanceDb:
    def __init__(self):
        self.Instances = {}
        self.count = 0

    def add_instance(self, instance):
        self.count += 1
        self.Instances[instance.id] = instance

    def debug(self):
        for instance_id in sorted(self.Instances.keys()):
            self.Instances[instance_id].debug()
